/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package basemodule;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.ImageIcon;

/**
 *
 * @author LENOVO
 */
public class RotatingClass extends javax.swing.JPanel  implements Runnable {

    /**
     * Creates new form RotatingClass
     */
    public RotatingClass() {
        initComponents();
        this.setSize(200, 200);
//         setBackground(Color.BLACK);
         setDoubleBuffered(true);
h = this.getHeight();
w = this.getWidth();
        ImageIcon ii = new ImageIcon(this.getClass().getResource("/basemodule/rotating Circles.png"));
        star = ii.getImage();

        theta = 0;
    }

    
    private Image star;
    private Thread animator;
    private int x, y,h,w;
private double theta;
    private final int DELAY = 50;


  
    public void addNotify() {
        super.addNotify();
        animator = new Thread(this);
        animator.start();
    }

    public void paint(Graphics g) {
        super.paint(g);

        Graphics2D g2d = (Graphics2D)g;
        g2d.rotate(theta,100,100);
        
        g2d.drawImage(star, 0, 0, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }


    public void cycle() {

        theta+=Math.toRadians(1);
        
        if(Math.toDegrees(theta)>=360)
            theta = 0;
    }

    public void run() {

        long beforeTime, timeDiff, sleep;

        beforeTime = System.currentTimeMillis();

        while (true) {

            cycle();
            repaint();

            timeDiff = System.currentTimeMillis() - beforeTime;
            sleep = DELAY - timeDiff;

            if (sleep < 0)
                sleep = 2;
            try {
                Thread.sleep(sleep);
            } catch (InterruptedException e) {
                System.out.println("interrupted");
            }

            beforeTime = System.currentTimeMillis();
        }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setOpaque(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 274, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 201, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
